#!/bin/bash
TARGET_FILE=dist.tar.gz
# shellcheck disable=SC2088
DEPLOY_DIR='~/binlog-frontend/'

npm run build || exit 1
cd dist || exit 1
tar zcv --owner=root --group=root -f $TARGET_FILE ./* || exit 1
scp $TARGET_FILE root@bincker.cn:/tmp/ || exit 1
# shellcheck disable=SC2087
ssh root@bincker.cn <<EOF
  cd $DEPLOY_DIR || exit 1
  rm -rf ./* || exit 1
  tar zxf /tmp/$TARGET_FILE -C ./ || exit 1
  rm /tmp/$TARGET_FILE
EOF
rm $TARGET_FILE
